import ezdxf
import openpyxl

# 打开 Excel 文件
wb = openpyxl.load_workbook("test.xlsx")

# 获取特定列的数据
sheet = wb.active
column_data = [cell.value for cell in sheet["A"]]
print(column_data)
# 提取点坐标
for cell in sheet["A"]:
    data = cell.value
    print(data)
    
data_list = data.split(',')
print(data_list)

# 提取数据
total_points = int(data_list[1])
elevation_range = (int(data_list[-5]), int(data_list[-4]))
coordinates = [(int(data_list[i+1]), int(data_list[i+2])) for i in range(2, len(data_list)-5, 3)]
print(coordinates)

# 创建CAD图纸
doc = ezdxf.new('R2000')
msp = doc.modelspace()


# 投影并连线
for i in range(len(coordinates)-1):
    point1 = coordinates[i]
    point2 = coordinates[i+1]
    msp.add_line(point1, point2)

# 保存CAD文件
doc.saveas("output.dxf")